home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / ncurses-5.3.lha / ncurses-5.3 / Ada95 / samples / rain.adb < prev    next >
Text File  |  2002-10-24  |  6KB  |  164 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                       GNAT ncurses Binding Samples                       --
  4. --                                                                          --
  5. --                                   Rain                                   --
  6. --                                                                          --
  7. --                                 B O D Y                                  --
  8. --                                                                          --
  9. ------------------------------------------------------------------------------
  10. -- Copyright (c) 1998 Free Software Foundation, Inc.                        --
  11. --                                                                          --
  12. -- Permission is hereby granted, free of charge, to any person obtaining a  --
  13. -- copy of this software and associated documentation files (the            --
  14. -- "Software"), to deal in the Software without restriction, including      --
  15. -- without limitation the rights to use, copy, modify, merge, publish,      --
  16. -- distribute, distribute with modifications, sublicense, and/or sell       --
  17. -- copies of the Software, and to permit persons to whom the Software is    --
  18. -- furnished to do so, subject to the following conditions:                 --
  19. --                                                                          --
  20. -- The above copyright notice and this permission notice shall be included  --
  21. -- in all copies or substantial portions of the Software.                   --
  22. --                                                                          --
  23. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  --
  24. -- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               --
  25. -- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   --
  26. -- IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   --
  27. -- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    --
  28. -- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    --
  29. -- THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               --
  30. --                                                                          --
  31. -- Except as contained in this notice, the name(s) of the above copyright   --
  32. -- holders shall not be used in advertising or otherwise to promote the     --
  33. -- sale, use or other dealings in this Software without prior written       --
  34. -- authorization.                                                           --
  35. ------------------------------------------------------------------------------
  36. --  Author:  Laurent Pautet <pautet@gnat.com>
  37. --  Modified by:  Juergen Pfeifer, 1997
  38. --  Contact: http://www.familiepfeifer.de/Contact.aspx?Lang=en
  39. --  Version Control
  40. --  $Revision: 1.5 $
  41. --  Binding Version 01.00
  42. ------------------------------------------------------------------------------
  43. --                                                                          --
  44. with Ada.Numerics.Float_Random; use Ada.Numerics.Float_Random;
  45. with Status; use Status;
  46. with Terminal_Interface.Curses; use Terminal_Interface.Curses;
  47.  
  48. procedure Rain is
  49.  
  50.    Visibility : Cursor_Visibility;
  51.  
  52.    subtype X_Position is Line_Position;
  53.    subtype Y_Position is Column_Position;
  54.  
  55.    Xpos    : array (1 .. 5) of X_Position;
  56.    Ypos    : array (1 .. 5) of Y_Position;
  57.  
  58.    N : Integer;
  59.  
  60.    G : Generator;
  61.  
  62.    Max_X, X : X_Position;
  63.    Max_Y, Y : Y_Position;
  64.  
  65.    procedure Next (J : in out Integer);
  66.    procedure Cursor (X : X_Position; Y : Y_Position);
  67.  
  68.    procedure Next (J : in out Integer) is
  69.    begin
  70.       if J = 5 then
  71.          J := 1;
  72.       else
  73.          J := J + 1;
  74.       end if;
  75.    end Next;
  76.  
  77.    procedure Cursor (X : X_Position; Y : Y_Position) is
  78.    begin
  79.       Move_Cursor (Line => X, Column => Y);
  80.    end Cursor;
  81.    pragma Inline (Cursor);
  82.  
  83. begin
  84.  
  85.    Init_Screen;
  86.    Set_NL_Mode;
  87.    Set_Echo_Mode (False);
  88.  
  89.    Visibility := Invisible;
  90.    Set_Cursor_Visibility (Visibility);
  91.  
  92.    Max_X := Lines - 5;
  93.    Max_Y := Columns - 5;
  94.  
  95.    for I in Xpos'Range loop
  96.       Xpos (I) := X_Position (Float (Max_X) * Random (G)) + 2;
  97.       Ypos (I) := Y_Position (Float (Max_Y) * Random (G)) + 2;
  98.    end loop;
  99.  
  100.    N := 1;
  101.    while Process.Continue loop
  102.  
  103.       X := X_Position (Float (Max_X) * Random (G)) + 2;
  104.       Y := Y_Position (Float (Max_Y) * Random (G)) + 2;
  105.  
  106.       Cursor (X, Y);
  107.       Add (Ch => '.');
  108.  
  109.       Cursor (Xpos (N), Ypos (N));
  110.       Add (Ch => 'o');
  111.  
  112.       --
  113.       Next (N);
  114.       Cursor (Xpos (N), Ypos (N));
  115.       Add (Ch => 'O');
  116.  
  117.       --
  118.       Next (N);
  119.       Cursor (Xpos (N) - 1, Ypos (N));
  120.       Add (Ch => '-');
  121.       Cursor (Xpos (N), Ypos (N) - 1);
  122.       Add (Str => "|.|");
  123.       Cursor (Xpos (N) + 1, Ypos (N));
  124.       Add (Ch => '-');
  125.  
  126.       --
  127.       Next (N);
  128.       Cursor (Xpos (N) - 2, Ypos (N));
  129.       Add (Ch => '-');
  130.       Cursor (Xpos (N) - 1, Ypos (N) - 1);
  131.       Add (Str => "/\\");
  132.       Cursor (Xpos (N), Ypos (N) - 2);
  133.       Add (Str => "| O |");
  134.       Cursor (Xpos (N) + 1, Ypos (N) - 1);
  135.       Add (Str => "\\/");
  136.       Cursor (Xpos (N) + 2, Ypos (N));
  137.       Add (Ch => '-');
  138.  
  139.       --
  140.       Next (N);
  141.       Cursor (Xpos (N) - 2, Ypos (N));
  142.       Add (Ch => ' ');
  143.       Cursor (Xpos (N) - 1, Ypos (N) - 1);
  144.       Add (Str => "   ");
  145.       Cursor (Xpos (N), Ypos (N) - 2);
  146.       Add (Str => "     ");
  147.       Cursor (Xpos (N) + 1, Ypos (N) - 1);
  148.       Add (Str => "   ");
  149.       Cursor (Xpos (N) + 2, Ypos (N));
  150.       Add (Ch => ' ');
  151.  
  152.       Xpos (N) := X;
  153.       Ypos (N) := Y;
  154.  
  155.       Refresh;
  156.       Nap_Milli_Seconds (50);
  157.    end loop;
  158.  
  159.    Visibility := Normal;
  160.    Set_Cursor_Visibility (Visibility);
  161.    End_Windows;
  162.  
  163. end Rain;
  164.